package com.aqie.medium.reservoirSampling;

/**
 * 398 随机数索引 todo
 */
public class RandomPickIndex {
    /**
     * 243ms
     */
    private int[] n;
    private int x = 0;

    public RandomPickIndex(int[] nums) {
        this.n = nums;
    }

    public int pick(int target) {
        do {
            if (x == n.length) {
                x = 0;
            }
        } while (n[x++] != target);
        return x - 1;

    }
}
